#pragma once
#include <mutex>
#include <atomic>
#include "zuc/nml_intf/zucpos2.h"
#include "ag_config.h"

// 提供axisgroup配置的设置
namespace axisgroup {
class AxisGroup;

class RobotSetIntf
{
public:
    RobotSetIntf(int id, AxisGroup* grp);
    virtual ~RobotSetIntf();
    int load_config(int serial_num);
    bool is_config_change() const { return is_config_change_; }
    void update_active_config();

private:
    int group_id_;
    AxisGroup* grp_;
    int serial_num_ = -1;  // 由配置文件加载而来
    std::atomic<bool> is_config_synced_ = false;
    std::atomic<bool> is_config_change_ = false;
    std::atomic<bool> is_dyn_related_change_ = false;
    AgConfig::RobotConfig active_config_;  // motion 生效的config, 每个周期同步给axisgroup

    AgConfig ag_config_;  // ag_config 会被task层改变，修改它需要加锁

public:
    std::mutex config_mutex_;
    AgConfig::RobotConfig* get_usr_config() { return &ag_config_.config_; }  // 还未生效的配置

public:
    void config_change();
    void write_usr_config_to_file();
    void sync_robot_config();
    void set_axisgroup_dh(const RobotDH& config, bool from_rt = false);
    void update_dyna_para();
    void set_payload(int id);
    void set_base_offset();

    static int get_serial_type(uint32_t serial_num);
    static int get_module_type(uint32_t serial_num);
    static int get_joint_num_by_serial_num(uint32_t serial_num);

public:
    int set_robot_joint_limit(std::string tag, int joint_num, double limit);
    int set_usr_frame(int id);
    int set_robot_tool(int id);
    int set_collision_lv(int lv);

    friend class AxisGroup;
    friend class Robot;
};
}  // namespace axisgroup